/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.view;

import com.controller.PengendaliPenerimaSuratDokument;
import com.model.Surat;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author priska
 */
public class FormSurat extends JDialog {

    private JLabel NomorSurat, Perihal, AsalSurat, Penerima, Letak, NamaPetugas, TanggalTerima;
    private JTextField JNomorSurat, JPerihal, JAsalSurat, JPenerima, JLetak, JNamaPetugas, JTanggalTerima;
    private JButton Simpan;

    public FormSurat() {
        this.setSize(300, 300);
        this.setLayout(null);
        this.setVisible(true);
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        this.setTitle(" Form Surat ");
    
    NomorSurat = new JLabel(" Nomor Surat ");
    NomorSurat.setBounds(10, 10, 100, 20);
    this.add(NomorSurat);
    
    Perihal = new JLabel(" Perihal ");
    Perihal.setBounds(10, 40, 100, 20);
    this.add(Perihal);
    
    AsalSurat = new  JLabel(" Asal Surat ");
    AsalSurat.setBounds(10, 70, 100, 20);
    this.add(AsalSurat);
    
    Penerima = new JLabel(" Penerima ");
    Penerima.setBounds(10, 100, 100, 20);
    this.add(Penerima);
    
    Letak = new JLabel(" Letak ");
    Letak.setBounds(10, 130, 100, 20);
    this.add(Letak);
    
    NamaPetugas = new JLabel(" Nama Petugas ");
    NamaPetugas.setBounds(10, 160, 100, 20);
    this.add(NamaPetugas);
    
    TanggalTerima = new JLabel(" Tanggal Terima ");
    TanggalTerima.setBounds(10, 190, 100, 20);
    this.add(TanggalTerima);
    
    JNomorSurat = new JTextField();
    JNomorSurat.setBounds(120, 10, 100, 20);
    this.add(JNomorSurat);
    
    JPerihal = new JTextField();
    JPerihal.setBounds(120, 40, 100, 20);
    this.add(JPerihal);
    
    JAsalSurat = new JTextField();
    JAsalSurat.setBounds(120, 70, 100, 20);
    this.add(JAsalSurat);
    
    JPenerima = new JTextField();
    JPenerima.setBounds(120, 100, 100, 20);
    this.add(JPenerima);
    
    JLetak = new JTextField();
    JLetak.setBounds(120, 130, 100, 20);
    this.add(JLetak);
    
    JNamaPetugas = new JTextField();
    JNamaPetugas.setBounds(120, 160, 100, 20);
    this.add(JNamaPetugas);
    
    JTanggalTerima = new JTextField();
    JTanggalTerima.setBounds(120, 190, 100, 20);
    this.add(JTanggalTerima);
    
    Simpan = new JButton(" SIMPAN ");
    Simpan.setBounds(100, 220, 100, 30);
    this.add(Simpan);
    Simpan.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                String a = JNomorSurat.getText();
                String b = JPerihal.getText();
                String c = JAsalSurat.getText();
                String d = JPenerima.getText();
                String f = JLetak.getText();
                String g = JNamaPetugas.getText();
                String h = JTanggalTerima.getText();
                Surat sr = new Surat();
                sr.setAsalSurat(c);
                sr.setNomorSurat(a);
                sr.setPerihal(b);
                sr.setPenerimaSurat(d);
                sr.setLetakSurat(f);
                sr.setPetugasPenerimaSurat(g);
                sr.setTanggal(h);
                PengendaliPenerimaSuratDokument.tambahSurat(sr);
                try {
                    PengendaliPenerimaSuratDokument.tambahtableSurat(sr);
                } catch (SQLException ex) {
                    Logger.getLogger(FormSurat.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    PengendaliPenerimaSuratDokument.simpanTabelSurat();
                } catch (SQLException ex) {
                    Logger.getLogger(FormSurat.class.getName()).log(Level.SEVERE, null, ex);
                }
                if(e.getSource()== Simpan) {
                    dispose();
                }
                JOptionPane.showMessageDialog(null, " Surat Tersimpan ");
            }
        });
    }
    
    
    }

